package Month11.Day25;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;


public class Test1 {
    public static void main(String[] args) {
    String path="D:\\中国玩家\\products.xml";
    SAXReader reader=new SAXReader();
    Document doc=null;
    try {
        doc = reader.read(new File(path));
    } catch (DocumentException e) {
        e.printStackTrace();
        return;
    }
    List<Element> list=doc.selectNodes("/shop/product");
    for (Element e:list){
        String itemno = e.selectSingleNode("itemno").getText();
        String name = e.selectSingleNode("name").getText();
        String price = e.selectSingleNode("price").getText();
        String unit = e.selectSingleNode("unit").getText();
        String stockcount= e.selectSingleNode("stockcount").getText();
        System.out.println("商品编号：" + itemno + "\t" + "商品名字：" + name + "\t" + "商品单价：" + price + "\t" + "库存：" + stockcount + unit);
    }

}
}
